package nettydemo;/*

 */

import java.nio.IntBuffer;

/**
 * @ClassName BasicBuffer
 * @Author Final
 * @Project DataStructures
 * buffer示例
 */
public class BasicBuffer {

    public static void main(String[] args) {

        //创建一个buffer，大小为5，可以存放五个int
        IntBuffer intBuffer=IntBuffer.allocate(5);

        for (int i=0;i<intBuffer.capacity();i++){
            intBuffer.put(i*2);
        }

        /**
         * 重要
         */
        //将buffer切换，读写切换
        intBuffer.flip();

        while (intBuffer.hasRemaining()){
            System.out.println(intBuffer.get());
        }

    }
}
